package Homework;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public class Homework05 {
    public static void main(String[] args) {
        // 定义一个集合作为牌堆
        ArrayList<String> a1 = new ArrayList<>();
        // 定义一个集合作为索引
        ArrayList<Integer> a2 = new ArrayList<>();
        // 存储花色
        String[] type = {"♠", "♣", "♥", "♦"};
        // 存储数字
        String[] num = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"};
        int a = 0;
        for (int i = 0; i < num.length; i++) {
            for (int j = 0; j < type.length; j++) {
                a2.add(a);
                a++;
                a1.add(type[j] + num[i]);
            }
        }
        a2.add(a);
        a1.add("小王");
        a++;
        a2.add(a);
        a1.add("大王");
        // 使用 shuffle方法洗牌
        Collections.shuffle(a2);
        // 定义玩家及底牌的集合
        ArrayList<Integer> player01 = new ArrayList<>();
        ArrayList<Integer> player02 = new ArrayList<>();
        ArrayList<Integer> player03 = new ArrayList<>();
        ArrayList<Integer> diPai = new ArrayList<>();
        for (int i = 0; i < a2.size() ; i++) {
            Integer in = a2.get(i);
            //先判断底牌
            if(i >= 51){
                //给底牌发牌
                diPai.add(in);
            }else if(i % 3 == 0){
                //给玩家1发牌
                player01.add(in);
            }else if(i % 3 == 1){
                //给玩家2发牌
                player02.add(in);
            }else if(i % 3 == 2){
                //给玩家3发牌
                player03.add(in);
            }
        }
        // 使用Collections类中的sort方法进行升序排列
        Collections.sort(player01);
        Collections.sort(player02);
        Collections.sort(player03);
        Collections.sort(diPai);
        // 使用Collections类中的reverse方法进行反转排列，实现从大到小
        Collections.reverse(player01);
        Collections.reverse(player02);
        Collections.reverse(player03);
        Collections.reverse(diPai);
        //  查看手中的牌
        System.out.println("player01手中的牌是：");
        for (Integer x: player01) {
            System.out.print(a1.get(x) + " ");
        }
        System.out.println();
        System.out.println("player02手中的牌是");
        for (Integer x: player02) {
            System.out.print(a1.get(x) + " ");
        }
        System.out.println();
        System.out.println("player03手中的牌是：");
        for (Integer x: player03) {
            System.out.print(a1.get(x) + " ");
        }
        System.out.println();
        System.out.println("底牌是：");
        for (Integer x: diPai) {
            System.out.print(a1.get(x) + " ");
        }
    }
}
